package se.webbzon.boltzmann.collision;

import java.lang.reflect.Array;
import java.util.Collection;

import se.webbzon.oschi01.worldobject.WorldStaticObject;

public class CollisionIgnorer<T extends WorldStaticObject> {
	
	// A stack containing all instances which should be ignored
	private T[] instanceStack;
	
	// A stack containing the solidity state of each instance to ignore
	private boolean[] solidityStack;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new collision ignorer which ignores the solidity of
	 * all the instances in the given collection. **/
	@SuppressWarnings("unchecked")
	public CollisionIgnorer(Class<T> clazz, Collection<T> ignoreInstances) {
		instanceStack = ignoreInstances.toArray((T[]) Array.newInstance(clazz, 0));
		solidityStack = new boolean[instanceStack.length];
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Ignores the instances of the collision ignorer. **/
	public void ignore() {
		for (int i = 0; i < instanceStack.length; i++) {
			solidityStack[i] = instanceStack[i].isSolid();
			instanceStack[i].setSolid(false);
		}
	}
	
	/** Resets all the instances of the collision ignorer. **/
	public void reset() {
		for (int i = 0; i < instanceStack.length; i++)
			instanceStack[i].setSolid(solidityStack[i]);
	}

}
